import $ from "jquery";
import {url} from "../../util/config";
import {message} from "antd";
import login from "../login";

function getNewLogin(item) {
    return insertDeptBind(item)
}

export default function insertDeptBind(item) {
    console.log(item)
    let token = localStorage.getItem("token")

    let status = null;
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
                'Authorization': token
        },
        url: url.api_url+`DeptBindRole/InsertDept`,
        type: 'POST',
         contentType:"application/json",
            data:JSON.stringify({
                DEPT_NO:item.deptNo,	//部门no
                BIND_ROLE_ID_LIST:item.bindRoleIdList
            }),
        success: function (result) {
            status = result.result;
            if(status=="Token過期請重新登錄") {
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(item)
            }else {
                if(status=="ok"){
                    message.success("新增成功");
                }else message.error("新增失败")
            }
        },
        error:function (error) {
            status = "error";
            message.error("请求异常")
        }
    })
    return status;

//  写ajax时把上面注释取消
//     return "ok"
}


